#!/usr/bin/sh

# Mod1:Alt, Mod4:Super 
mod1=Mod1
mod0=Mod4
term0="foot"


riverctl map normal ${mod0} q close
riverctl map normal ${mod0} w spawn "swaylock.sh"
riverctl map normal ${mod0} e spawn "${HOME}/.local/bin/exitriver"

riverctl map normal ${mod0} a spawn "$HOME/.local/bin/address"
riverctl map normal ${mod0} s spawn "${HOME}/.local/bin/swayhibe"
riverctl map normal ${mod0} d toggle-float

riverctl map normal ${mod0} z zoom
riverctl map normal ${mod0} x spawn "$HOME/.local/bin/wclip"
riverctl map normal ${mod0} c spawn "${HOME}/.config/river/init"
riverctl map normal ${mod0} n spawn "${HOME}/.local/bin/wmenu-run-color -i" # Case-insensitive launcher

riverctl map normal Control space spawn "fcitx5-remote -t && notify-send -u normal -r 3289 -t 1100 $(fcitx5-remote -n)"


# abcdefghijklmnopqrstuvwxyz
# AbCDeFGHIJkLMNOPqRsTUVwXYZ

riverctl map normal ${mod0} Space focus-previous-tags 
riverctl map normal ${mod0} Return toggle-fullscreen

#
riverctl map normal ${mod0}+Shift v spawn "${term0} -T \"Floating_Term\" abduco -A dvtm"
#riverctl map normal ${mod0} x                          spawn "dunstctl history-pop"
riverctl map normal ${mod0}+Shift x spawn "dunstctl close"

# TODO no response
# riverctl map normal ${mod0}+shift m send-layout-cmd $tiler "main-count +1"
# riverctl map normal ${mod0} m send-layout-cmd $tiler "main-count -1"


# Control mpc
riverctl map normal ${mod0} p spawn "mpc toggle"

# window rules
#riverctl rule-add -title "Floating_Term" float


hi_keys=('r' 't' 'f' 'g' 'v' 'b' 'y' 'u' 'i' 'o' 'p' 'm' '3')

for i in "${!hi_keys[@]}"; do
  # 绑定 Super + x 来启动 x
  riverctl map normal ${mod0} ${hi_keys[$i]} spawn "~/.config/river/smart_launch.sh ${hi_keys[$i]}"
  riverctl map normal ${mod1} ${hi_keys[$i]} spawn "~/.config/river/smart_launch.sh +${hi_keys[$i]}"
done



# riverctl map normal ${mod0} g spawn "$HOME/.local/bin/wshot" # swich screen monitor
# riverctl map normal ${mod0}+Shift g                  spawn "$HOME/.local/bin/wshot-geo"
# riverctl map normal ${mod0}+Control g                spawn "grim && notify-send -u low -r 88 \"Screenshot taken on all outputs\""



riverctl map normal ${mod0}+Shift a spawn "$HOME/.local/bin/address --record"
riverctl map normal ${mod0}+Control a spawn "$HOME/.local/bin/address --multi"


#
riverctl map -repeat normal ${mod0} h send-layout-cmd $tiler "main-ratio -0.05"
riverctl map -repeat normal ${mod0} l send-layout-cmd $tiler "main-ratio +0.05"

riverctl map normal ${mod0} h focus-view left
riverctl map normal ${mod0} j focus-view next
riverctl map normal ${mod0} k focus-view previous
riverctl map normal ${mod0} l focus-view right

riverctl map normal ${mod0}+Shift h swap left
riverctl map normal ${mod0}+Shift j swap next
riverctl map normal ${mod0}+Shift k swap previous
riverctl map normal ${mod0}+Shift l swap right


#
riverctl map -repeat normal ${mod0}+Control minus send-layout-cmd $tiler "gaps +2"
riverctl map -repeat normal ${mod0}+Control equal send-layout-cmd $tiler "gaps -2"



#
# riverctl map normal ${mod0} t                          send-layout-cmd "$tiler" "main-location left"
# riverctl map normal ${mod0}+Shift t                  send-layout-cmd "$tiler" "main-location right"
# riverctl map normal ${mod0} u send-layout-cmd "$tiler" "main-location bottom"
# riverctl map normal ${mod0}+Shift u                  send-layout-cmd "$tiler" "main-location top"
# riverctl map normal ${mod0} ?                           send-layout-cmd "$tiler" "main-location monocle"

# no idea
# riverctl map normal ${mod0} period                     focus-output next
# riverctl map normal ${mod0} comma                      focus-output previous
# riverctl map normal ${mod0}+Shift period             send-to-output next
# riverctl map normal ${mod0}+Shift comma              send-to-output previous
#
# riverctl map normal ${mod0} apostrophe                 spawn "river-shifttags --occupied"
# riverctl map normal ${mod0} semicolon                  spawn "river-shifttags --shift -1 --occupied"
#
#
#
# # mouse
riverctl map-pointer normal ${mod0} BTN_LEFT move-view
riverctl map-pointer normal ${mod0} BTN_RIGHT resize-view
riverctl map-pointer normal ${mod0} BTN_MIDDLE toggle-float

## audioctl
riverctl map normal ${mod1} backspace spawn "$HOME/.local/bin/audio sink --mute"
riverctl map normal ${mod1}+Shift backspace spawn "$HOME/.local/bin/audio source --mute"

riverctl map -repeat normal ${mod1} minus spawn "$HOME/.local/bin/audio sink --minus"
riverctl map -repeat normal ${mod1} equal spawn "$HOME/.local/bin/audio sink --plus"

riverctl map -repeat normal ${mod1}+Shift minus spawn "$HOME/.local/bin/audio source --minus"
riverctl map -repeat normal ${mod1}+Shift equal spawn "$HOME/.local/bin/audio source --plus"

#  brightness ctrl
riverctl map -repeat normal ${mod1} bracketleft spawn "$HOME/.local/bin/bright --minus"
riverctl map -repeat normal ${mod1} bracketright spawn "$HOME/.local/bin/bright --plus"

